package org.apache.ibatis.demo.plugs;

import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;

import java.util.Properties;

/**
 * SqlLogInterceptor
 *
 * @author zhaohui
 * @date 2019/11/20 15:36
 */
//@Intercepts({@Signature(type = ResultSetHandler.class, method = "selectAll", args = {MappedStatement.class, Object.class})})
public class SqlLogInterceptor implements Interceptor {

    private Properties properties = new Properties();

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        System.out.println(properties);
        return invocation.getTarget();
    }

    @Override
    public Object plugin(Object target) {
        return target;
    }

    @Override
    public void setProperties(Properties properties) {
        this.properties = properties;
    }
}
